package org.springframework.boot;

import org.springframework.core.env.PropertySource;
import org.springframework.core.env.SimpleCommandLinePropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

/***
 * 环境配置
 * @author Administrator
 *
 */
public class Step3 {
    public static void main(String[] args) throws IOException {
        ApplicationEnvironment env = new ApplicationEnvironment(); // 系统环境变量, properties, yaml
        env.getPropertySources().addLast(new ResourcePropertySource(new ClassPathResource("application.properties")));//读取配置 文件addLast方法说明 级别最低
        env.getPropertySources().addFirst(new SimpleCommandLinePropertySource(args));//读取命令行   addFirst说明级别最高
        for (PropertySource<?> ps : env.getPropertySources()) {
            System.out.println(ps);
        }
       System.out.println(env.getProperty("JAVA_HOME"));

        System.out.println(env.getProperty("server.port"));
    }
}
